<?php
$sql = "SELECT t1.*, t1.top_sale, t3.price, t3.pid, t2.images, t2.thumbnail FROM tblproduct as t1 " .
        "INNER JOIN tblimage as t2 on t1.id=t2.product_id " .
        "INNER JOIN tblproduct_in_pharmacy as t3 on t1.id=t3.product_id " .
        "WHERE t1.status = 1 ORDER BY t1.top_sale DESC LIMIT 0,5";
$result = mysql_query($sql);
$i = 1;
$border = "";
while ($row = mysql_fetch_assoc($result)) {
    if ($i % 4 == 1) {
        echo '<div class="row-fluid box-product">';
    }
    $article = $row['product_name'];
    ?>     
    <div class="span3 product_block">
        <div class="product-inner feature-inner">
            <div class="image">
                <a href="<?php echo base_url; ?>/product/product_detail.php?product_id=<?php echo $row['id'] ?>"><img class="image_product_tap" src="<?php echo W_S_IMAGES_DIR . $row['images'] ?>" /></a>
            </div>
            <div class="wrap-infor"><div class="name">
                    <a href="<?php echo base_url; ?>/product/product_detail.php?product_id=<?php echo $row['id'] ?>"><?php echo $readmore = rm($article, $char); ?></a>
                </div>
            </div>
            <div class="price">$<?php echo $row['price'] ?></div>        
        </div>    
    </div>
    <?php
    if ($i % 4 == 0) {
        echo "</div>";
    }
    $i++;
}
if ($i % 4 != 1)
    echo "</div>";
?> 